package com.vogue.supplymall.order.domain.service.impl;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.mysql.fabric.xmlrpc.base.Data;
import com.vogue.ssm.database.dao.BaseDao;
import com.vogue.supplymall.common.domain.dto.CommentDefaultAnswerInfo;
import com.vogue.supplymall.order.domain.dao.CommentDefaultAnswerDao;
import com.vogue.supplymall.order.domain.model.CommentDefaultAnswer;
import com.vogue.supplymall.order.domain.service.CommentDefaultAnswerService;

@Service("commentDefaultAnswerService")
public class CommentDefaultAnswerServiceImpl extends BaseServiceImpl<CommentDefaultAnswer, Long> implements CommentDefaultAnswerService{
	
	@Resource
	private CommentDefaultAnswerDao commentDefaultAnswerDao;
	
	public CommentDefaultAnswerServiceImpl(BaseDao<CommentDefaultAnswer, Long> baseDao) {
		super(baseDao);
	}
	
	@Override
	public void saveDefaultMsg(CommentDefaultAnswerInfo cdaInfo) throws Exception{
		//对默认回复信息采用先删后插的方式
		Long syscodeId=cdaInfo.getSellerSyscodeId();
		Long shopId=cdaInfo.getShopId();
		String answerText=cdaInfo.getAnswerText();
		
		//根据syscodeId和shopId删除默认回复信息
		Map<String, Object> paramMap=new HashMap<>();
		paramMap.put("syscodeId", syscodeId);
		paramMap.put("shopId", shopId);
		
		this.delete0(commentDefaultAnswerDao.delDefaultMsg(), paramMap);
		
		//保存默认回复信息
		CommentDefaultAnswer cda=new CommentDefaultAnswer();
		cda.setAnswertext(answerText);
		cda.setSellersyscodeid(syscodeId);
		cda.setShopid(shopId);
		cda.setCreateDate(new Date());
		cda.setModifyDate(new Date());
		
		commentDefaultAnswerDao.save(cda);
	}
}
